<template>
	<view>
		<z-paging ref="paging" v-model="dataList" @query="getDataListAll" :show-loading-more-no-more-view="false" >
			<view slot="top">
				<u-navbar title="兑换中心" placeholder :autoBack="true" leftIconColor="#E6A5B4" bgColor="#FFFFFF"
					:titleStyle="titleStyle">
				</u-navbar>
			</view>
			<view @click="onInfoClick(item)" class="itemV" v-for="(item,index) in dataList" :key="index">
				<image class="imageV" mode="aspectFill" :src="item.image"></image>
				<view class="centerV">
					<view class="titleTv">{{item.title}}</view>
					<view class="bunV">
						<view class="bunV2">
							<view class="bunTv1">¥</view>
							<view class="bunTv2">{{item.price}}</view>
						</view>
						<view class="bunTv3" @click="onRedeemNowClick(item)">立即兑换</view>
					</view>
				</view>
			</view>
		</z-paging>
		<u-popup :show="isRedeemNow" mode="center" customStyle="width:70%; background-color: #00000000;">
			<view class="pupRedeemNowV">
				<text class="pupRedeemNowTv1">确认兑换</text>
				<text class="pupRedeemNowTv2">确定兑换{{orderItem.price}}元{{orderItem.title}}课程?</text>
				<view class="pupRedeemNowBtV">
					<text class="pupRedeemNowTv3" @click="isRedeemNow = false">取消</text>
				 	<text class="pupRedeemNowTv4" @click="onSumClick">确认</text>
				</view>
			</view>
		</u-popup>
		<u-popup :show="isSuccess" mode="center" customStyle="width:50%; background-color: #00000000;">
			<view class="pupSuccessV">
				<image class="pupSuccessIv" src="../../static/ok.png"></image>
				<text class="pupSuccessTv1">恭喜兑换成功！</text>
				<text class="pupSuccessTv2" @click="onSumToClick">确定</text>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					"color": "#ffffff"
				},
				dataList:[],
				orderItem: null,
				isRedeemNow: false,
				isSuccess: false,
			}
		},
		methods: {
			getDataListAll(pageNo, pageSize) {
				this.$api.getCardComboList({
					page: pageNo,
				}).then((res) => {
					this.$refs.paging.complete(res.list);
				}).catch((e) => {
					this.$refs.paging.complete(false);
				})
			},
			onRedeemNowClick(item) { //立即兑换
				this.orderItem = item;
				this.isRedeemNow = true;
			},
			onSumClick(){//确定
				this.$api.getDuihuanCard({
					id:this.orderItem.id,
					type:'combo'
				}).then((res) => {
					this.isRedeemNow = false;
					this.isSuccess = true;
				}).catch((e) => {
					uni.$u.toast(e.msg === undefined ? "兑换失败" : e.msg)
				})
			},
			onSumToClick(){
				this.isSuccess = false;
				this.$refs.paging.reload();
			}
		}
	}
</script>

<style lang="scss">
	.itemV {
		display: flex;
		margin-left: 30rpx;
		margin-right: 30rpx;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		border-bottom: 0.1rpx solid #383838;
	}

	.imageV {
		width: 200rpx;
		height: 200rpx;
		border-radius: 10rpx;
	}

	.centerV {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 30rpx;

		.titleTv {
			color: #e8e8e8;
			font-size: 32rpx;
		}

		.bunV {
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;

			.bunV2 {
				display: flex;
				align-items: baseline;

				.bunTv1 {
					font-size: 40rpx;
					color: #E6A5B4;
				}

				.bunTv2 {
					font-size: 50rpx;
					color: #E6A5B4;
				}
			}

			.bunTv3 {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 200rpx;
				height: 70rpx;
				background: #E6A5B4;
				border-radius: 35rpx;
				font-size: 28rpx;
				color: #333333;
			}

			.bunTv4 {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 200rpx;
				height: 70rpx;
				background: #4a4a4a;
				border-radius: 35rpx;
				font-size: 28rpx;
				color: #959595;
			}
		}
	}

	.pupRedeemNowV {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		background: #1f1f1f;
		border-radius: 30rpx;
	}

	.pupRedeemNowTv1 {
		color: #e8e8e8;
		font-size: 34rpx;
		font-weight: 500;
		display: flex;
		align-items: center;
		justify-content: center;
		padding-top: 40rpx;
	}

	.pupRedeemNowTv2 {
		color: #8D8D8D;
		font-size: 32rpx;
		font-weight: 400;
		margin-top: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex: 1;
		text-align: center;
	}

	.pupRedeemNowBtV {
		display: flex;
		height: 100rpx;
		width: 100%;
		margin-top: 30rpx;
	}

	.pupRedeemNowTv3 {
		background: #3D3F3E;
		color: #c2c2c2;
		font-size: 32rpx;
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom-left-radius: 30rpx;
	}

	.pupRedeemNowTv4 {
		background: #CEF743;
		color: #333737;
		font-size: 32rpx;
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom-right-radius: 30rpx;
	}

	.pupSuccessV {
		height: 380rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #333;
		border-radius: 30rpx;
	}
	.pupSuccessIv{
		width: 147rpx;
		height: 93rpx;
	}
	.pupSuccessTv1{
		color: #e8e8e8;
		font-size: 34rpx;
		font-weight: 500;
		margin-top: 20rpx;
	}
	.pupSuccessTv2{
		margin-top: 30rpx;
		border-radius: 35px;
		background: #E6A5B4;
		width: 200rpx;
		height: 70rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-weight: 500;
		color: #333;
	}
</style>